package com.zz.admin.common.auth;

import com.zz.admin.auth.dto.DefaultUserDetails;
import com.zz.admin.userManagement.dto.UserDto;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class AuthUtils {

    public static UserDto getCurrUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        DefaultUserDetails defaultUserDetails;
        try {
            defaultUserDetails = (DefaultUserDetails) authentication.getPrincipal();
        } catch (Exception e) {
            return null;
        }
        return defaultUserDetails.getUserDto();

    }
}
